package cn.daichi.redisidempotency.controller;

import cn.daichi.redisidempotency.annotation.Idempotency;
import cn.daichi.redisidempotency.base.Result;
import cn.daichi.redisidempotency.service.IdempotencyService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/idempotency")
public class IdempotencyController {

    private final IdempotencyService idempotencyService;


    public IdempotencyController(IdempotencyService idempotencyService) {
        this.idempotencyService = idempotencyService;
    }

    @GetMapping("/createToken")
    public Result createIdempotencyToken() {
        return Result.success(idempotencyService.createIdempotencyToken());
    }

    @Idempotency
    @GetMapping("/test")
    public Result testIdempotency() {
        return Result.success("幂等性测试成功");
    }
}
